//Programs TABLE3A and TABLE3B produce the results in TABLE 3.
//The programs are intended to be run in tandem, with program A run first.
//It takes approximately 30 minutes on a laptop to run 10,000 iterations.

clear
set more off
drop _all
log using "\\file\UsersW$\wrr15\Home\My Documents\My Files\HURWICZ BIAS\REVISION FOR ECONOMIC MODELLING\PROGRAMS2\TABLE3.smcl", replace
etime, start
set seed 13


matrix Wald = J(5,3,0)
matrix Fieller = J(5,3,0)

local i = 1
foreach betay in 0.60 0.70 0.80 0.90 0.95 {
   local j = 1
   foreach smallobs in 10 50 1000 {
      simulate pWald = r(pWald) pFieller = r(pFieller), ///
         reps(10000): FIELLERprog, betay(`betay') smallobs(`smallobs') bigobs(1100) ///
		 beta0(0)  betax(1)
		 
      generate RRWald = 0
      replace RRWald = 1 if pWald < 0.05  
	  summ RRWald, meanonly
      matrix Wald[`i', `j'] = r(mean)
	  
      generate RRFieller = 0
      replace RRFieller = 1 if pFieller < 0.05  
	  summ RRFieller, meanonly
      matrix Fieller[`i', `j'] = r(mean)
      local `++j'
   }
   local `++i'
}

matrix colnames Wald = T10 T50 T1000
matrix rownames Wald = B60 B70 B80 B90 B95

matrix colnames Fieller = T10 T50 T1000
matrix rownames Fieller = B60 B70 B80 B90 B95

matrix list Wald
matrix list Fieller

etime

log close
